﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prices
{
    public class Product : IPriceIncresedNotification
    {
        private string name = default(string);
        private decimal price = default(decimal);

        public string Name
        {
            get { return this.name; }
        }
        public decimal Price
        {
            get { return this.price; }
            set
            {
                if (this.price < value)
                {
                    OnPriceIncresed(this.price, value);
                }
                this.price = value;
            }
        }

        public Product(string name, decimal price)
        {
            if (name == null)
            {
                throw new ArgumentNullException("Name cannot be null");
            }
            if (price < 0)
            {
                throw new ArgumentException("Price cannot be negative");
            }
            this.name = name;
            this.price = price;
        }

        public event PriceIncresedEventHandler PriceIncresed;

        protected void OnPriceIncresed(decimal oldPrice, decimal newPrice)
        {
            if (PriceIncresed != null)
            {
                PriceIncresed(this, new PriceIncresedEventArgs(oldPrice, newPrice));
            }
        }
    }
}
